<?php
 
$form = $this->element;

$id = Zend_Controller_Front::getInstance()->getRequest()->getParam('id');
$callbackRow = CallbackPeer::getInstance()->fetchById($id);

?>
<form enctype="multipart/form-data" method="post" action="">

	<?php 
	
	/**
     * Translate some form errrors.
     * 
     * @param string $key
     * @param string $error
     * @return string
     */
    function _translate($key, $error)
    {
    	$_translated = array(
			'isEmpty' => 'Поле обязательно для заполнения',
		);
	
    	if (isset($_translated[$key])) {
    		return $_translated[$key];
    	}
    	
    	return $error;
    }
    
    $errors = $form->getMessages();
    foreach ($errors as $key => $error) {
    	if (is_array($error)) {
    		unset($errors[$key]);
    	}

   		if (is_array($error)) {
     		foreach ($error as $k => $v) {
     			$label = $form->getElement($key)->getLabel();
     			$v = _translate($k, $v);
     			$errors[$key][$k] = "$label -- $v";
     		}
    	} else {
    		$errors[$key] = _translate($key, $error);
    	}
    }
    
    if ($errors) {
	    echo "<ul class='errors'>";
	    foreach ($errors as $error) {
	    	if (is_array($error)) {
	    		foreach ($error as $k => $v) {
	    			echo "<li>$v</li>";
	    		}
	    	} else {
	    		echo "<li>$error</li>";
	    	}
	    }
	    echo "</ul>";
    }
	
	
	?>


	<div>
	    <dl class="floater-3">
			<?php echo $callbackRow->getCreatedAt(); ?>
			<input type="hidden" name="created_at" value="<?php echo $callbackRow->getCreatedAt()?>"/>
	    </dl>
	    
	    <dl class="floater-3">
			<?php echo $form->getElement('fio'); ?>
	    </dl>
	    
	    <dl class="floater-3">
			<?php echo $form->getElement('phone'); ?>
	    </dl>
	    
	    <dl class="floater-3">
			<?php echo $form->getElement('comment'); ?>
	    </dl>
	    
	    <?php 
	    	$statusRowset = OrdersService::getInstance()->getCallbackStatuses(); 
	    	$stElement = $form->getElement('status_id');
	    ?>
	    <dl class="floater-3">
	    	<select name="status_id">
	    		<?php foreach ($statusRowset as $statusRow):?>
	    			<option value="<?php echo $statusRow->getId();?>" 
	    				<?php if ($stElement->getValue() == $statusRow->getId()){echo 'selected="selected"';}?>>
	    				<?php echo $statusRow->getName();?>
	    			</option>
	    		<?php endforeach; ?>
	    	</select>
	    </dl>
	    
		<dt id="submit-label">&nbsp;</dt>
		<dd id="submit-element">
			<input type="submit" name="submit" id="submit" value="Сохранить" />
			<?php echo $form->getElement('crud_exit'); ?>
		</dd>
	</div>
</form>